package com.qiwx.pigeon.presenter;


import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseListResponse;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.CageParam;
import com.qiwx.pigeon.data.params.ChartParam;
import com.qiwx.pigeon.data.params.QueryCageParam;
import com.qiwx.pigeon.data.params.SearchParam;
import com.qiwx.pigeon.data.vo.EggLoseBean;
import com.qiwx.pigeon.data.vo.LayEggAmountBean;
import com.qiwx.pigeon.data.vo.QueryCageBean;
import com.qiwx.pigeon.data.vo.QueryFertilizedBean;
import com.qiwx.pigeon.data.vo.CageProduceBean;
import com.qiwx.pigeon.data.vo.SummaryOther;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.viewinterface.IQueryCageView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * @description
 * @Author qiwx
 * @Date 2020-04-16 11:30
 **/
public class QueryCagePresenter extends BasePresenter<IQueryCageView> {

    public QueryCagePresenter(WeakReference<IQueryCageView> from) {
        super(from);
    }

    //搜索鸽笼
    public void searchCage(SearchParam params) {
        ApiManager.getApiServer().searchCage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<CageProduceBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        getView().onFailure("搜索");
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<CageProduceBean> response) {
                        getView().onSearchSuccess(response.data);
                    }

                });
    }

    //查询鸽笼受精情况
    public void queryCageFertilizeByPage(QueryCageParam params) {
        ApiManager.getApiServer().queryCageFertilizeByPage(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<CageProduceBean>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onFailure(String error) {
                        super.onFailure(error);
                        getView().onFailure(error);

                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<CageProduceBean>> response) {
                        getView().onQueryCageSuccess(response.data);
                    }

                });
    }

    //添加淘汰鸽笼
    public void addCageEliminate(CageParam params) {
        ApiManager.getApiServer().addCageEliminate(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onAddCageEliminateSuccess(1);
                    }

                });
    }


    //查询下蛋统计
    public void queryLayEggAmount(ChartParam params) {
        ApiManager.getApiServer().queryLayEggAmount(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseListResponse<LayEggAmountBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseListResponse<LayEggAmountBean> response) {
                        getView().onQueryLayEggSuccess(response.data);
                    }

                });
    }

    //查询下蛋统计
    public void queryEggLoseAmount(ChartParam params) {
        ApiManager.getApiServer().queryEggLoseAmount(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseListResponse<EggLoseBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseListResponse<EggLoseBean> response) {
                        getView().onQueryEggLoseSuccess(response.data);
                    }

                });
    }

    //查询下蛋统计
    public void queryShoujAmount(ChartParam params) {
        ApiManager.getApiServer().queryShoujAmount(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseListResponse<QueryFertilizedBean>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseListResponse<QueryFertilizedBean> response) {
                        getView().onQueryShoujSuccess(response.data);
                    }

                });
    }

    //查询其他
    public void queryOtherAmount(ChartParam params) {
        ApiManager.getApiServer().queryOtherAmount(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseListResponse<SummaryOther>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseListResponse<SummaryOther> response) {
                        getView().onQueryOtherSuccess(response.data);
                    }

                });
    }

}
